<template>
  <div id="modifyRecord">
    <!-- 上部搜索条件 -->
    <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
    <!-- 操作按钮部分 -->
    <div class="table-conBtn">
      <freshCom @searchList="searchList"></freshCom>
    </div>
    <!-- 表格部分 -->
    <el-table
      v-loading="loading"
      :data="tableData"
      style="width: 100%"
      max-height="490"
      ref="table"
    >
      <el-table-column type="index" width="60" label="序号">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="修改时间"
        min-width="150"
      ></el-table-column>
      <el-table-column
        prop="operatorUser.userName"
        label="修改人"
        min-width="130"
      ></el-table-column>
      <el-table-column
        prop="dpAccountUser.userName"
        label="用户昵称"
        min-width="130"
      ></el-table-column>
      <el-table-column
        prop="dpAccount"
        label="用户大鹏号"
        min-width="130"
      ></el-table-column>
      <el-table-column prop="title" label="积分变动" min-width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.integralChangeType" class="greenText"
            >+ {{ scope.row.integralChangeNumber }}</span
          >
          <span v-else class="redText"
            >- {{ scope.row.integralChangeNumber }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        prop="integralChangeReason"
        label="变更原因"
        min-width="150"
      ></el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
  </div>
</template>
<script>
import topSearch from '@component/intergralManagement/modifyRecord/topSearch' // 上部搜索条件
import { saveScrollMixins } from '@/mixins/saveScroll'
import { changesRecord } from '@/api/couponsIntegral/integrals' //接口
export default {
  name: 'modifyRecord',
  msg: '用户成长体系-修改积分记录',
  mixins: [saveScrollMixins],
  components: {
    topSearch
  },
  data() {
    return {
      loading: false,
      total: 0,
      // 搜索条件
      formInline: {
        operator: '', // 修改人
        dpAccount: '', // 用户大鹏号
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        createTime: []
      },
      // 表格数据
      tableData: [],
      // 分页数据
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      }
    }
  },
  activated() {
    this.toTableScrollHeight()
  },
  mounted() {
    // 获取权限
    // this.getPower()
    this.searchList()
    this.$nextTick(() => {
      setTimeout(() => {
        this.setTableScrollHeight()
      }, 1000)
    })
  },
  methods: {
    /* 获取列表 */
    searchList() {
      this.loading = true
      let obj = Object.assign({}, this.searchParams, this.formInline)
      delete obj.createTime
      changesRecord(
        obj,
        (response) => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    /* 编辑后，刷新列表 */
    refresh() {
      this.searchList()
    },
    /* 搜索 */
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    }
  }
}
</script>
<style lang="less">
#modifyRecord {
  .greenText {
    color: #03aa87;
  }
  .redText {
    color: #f00;
  }
}
</style>
